﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Core.WeiXin;
using Xproject.Util;

namespace WeiXinProject
{
    public partial class WXLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                GotoOAuth();
            }
        }

        void GotoOAuth()
        {
            string gotoUrl = this.Request.QueryString["gotoUrl"] ?? "";
            object obj = Session["1-wxbase_user"];
            if (obj == null)
            {
                if (!string.IsNullOrEmpty(gotoUrl))
                {
                    gotoUrl = HttpUtility.HtmlDecode(gotoUrl);
                    Session["gotoUrl"] = gotoUrl;
                }
                   string url = CommonHelper.GetAppSettings("Domain")+"/Login/Index?gotoUrl=" + HttpUtility.UrlEncode( gotoUrl) + "&from=wxback";
                //string url = CommonHelper.GetAppSettings("Domain") + "/Login/Index";
              
               // LogHelper.WriteFlag(" loginWX.aspx GotoOAuth  abcd  " + "url = " + url);
                url = WeiXinHelper.GetCodeUrl(url);
               
              //  LogHelper.WriteFlag(" loginWX.aspx GotoOAuth  37  " + "  weixin  auth2.0 url = " + url);
                Response.Redirect( url);
               
            }
            else
            {
                Response.Redirect(CommonHelper.GetAppSettings("Domain")+"/Shop/Index");
            }
        }

    }
}